package org.lex.string;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class XmlUtils {
	public static String format(Document doc) {
		StringWriter out = new StringWriter();
		try {
			format(doc, out);
			return out.toString();
		} catch (Throwable e) {
			return doc.asXML();
		}
	}

	public static void format(Document doc, Writer out) throws IOException {
		new XMLWriter(out, OutputFormat.createPrettyPrint()).write(doc);
	}
}
